import React from "react";
import { Form, Input, Button, message } from "antd";
import { UserOutlined, LockOutlined } from "@ant-design/icons";
import { loginByPassword } from "@/api/login";
import { useHistory } from "react-router-dom";
const AccountLogin = () => {
    const history = useHistory();
    return (
        <>
            <Form
                onFinish={formData => {
                    loginByPassword(formData).then(res => {
                        if (res.code === 200) {
                            message.success("登陆成功");
                            setTimeout(() => {
                                history.push("/main");
                            }, 500);
                        }
                    });
                }}
                labelCol={{ span: 5 }}
            >
                <Form.Item name="username" rules={[{ required: true, message: "请输入用户名/邮箱" }]}>
                    <Input size="large" prefix={<UserOutlined />} placeholder="用户名/邮箱" />
                </Form.Item>
                <Form.Item name="password" rules={[{ required: true, message: "请输入密码" }]}>
                    <Input.Password minLength={6} size="large" prefix={<LockOutlined />} placeholder="密码" />
                </Form.Item>
                <Form.Item>
                    <Button htmlType="submit" size="large" block type="primary">
                        登录
                    </Button>
                </Form.Item>
            </Form>
        </>
    );
};

export default AccountLogin;
